package com.tiany.java_study;

public class Animal {
    public String name;
    private int age;//私有化
    private int legs;

    //封装性的一种体现
    public void eat() {
        System.out.println(name + " is eating");

    }

    public void show() {
        System.out.println("name: " + name + "  age: " + age + "    legs: " + legs);
    }

    public void setLegs(int l) {
        if (l >= 0 && l / 2 == 0) {
            legs = l;
        } else legs = -1;
    }

    public void setAge(int a) {
        if (a > 0) {
            age = a;
        } else age = -1;
    }
}
